﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient


''' <summary>
''' Clase de la capa de acceso a datos DAL que implementa el patrón Table Data Gateway para el manejo de la entidad Entrevista
''' </summary>
''' <remarks></remarks>
Public Class TDGEntrevista

    Private Shared m_Instance As TDGEntrevista = Nothing


    Public Function Insert(conn As SqlConnection, _
                                        Soli_Numero As Int32, _
                                        Ent_Fecha As DateTime, _
                                        Ent_Hora As String, _
                                        Ent_Lugar As String, _
                                        TEnt_Codigo As Int16, _
                                        Ent_Realizada As Boolean, _
                                        Ent_Detalle As String, _
                                        Ent_Obs As String, _
                                        DVH As Int32, _
                                        Optional ByRef Ent_Numero As Int16 = 0) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16

        Dim outParam_Ent_Numero As SqlParameter


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.addEntrevista"
        command.Parameters.AddWithValue("@Soli_Numero", Soli_Numero)
        command.Parameters.AddWithValue("@Ent_Fecha", Ent_Fecha)
        command.Parameters.AddWithValue("@Ent_Hora", Ent_Hora)
        command.Parameters.AddWithValue("@Ent_Lugar", Ent_Lugar)
        command.Parameters.AddWithValue("@TEnt_Codigo", TEnt_Codigo)
        command.Parameters.AddWithValue("@Ent_Realizada", Ent_Realizada)
        command.Parameters.AddWithValue("@Ent_Detalle", Ent_Detalle)
        command.Parameters.AddWithValue("@Ent_Obs", Ent_Obs)
        command.Parameters.AddWithValue("@DVH", DVH)

        outParam_Ent_Numero = command.Parameters.Add("@Ent_Numero", SqlDbType.SmallInt)
        outParam_Ent_Numero.Direction = ParameterDirection.InputOutput



        iRowsAffected = command.ExecuteNonQuery()


        ' Retorno valores
        Ent_Numero = outParam_Ent_Numero.Value

        Return iRowsAffected

    End Function

    Public Function Update(conn As SqlConnection, _
                                                Soli_Numero As Int32, _
                                                Ent_Numero As Int16, _
                                                Ent_Fecha As DateTime, _
                                                Ent_Hora As String, _
                                                Ent_Lugar As String, _
                                                TEnt_Codigo As Int16, _
                                                Ent_Realizada As Boolean, _
                                                Ent_Detalle As String, _
                                                Ent_Obs As String, _
                                                DVH As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.updEntrevista"
        command.Parameters.AddWithValue("@Soli_Numero", Soli_Numero)
        command.Parameters.AddWithValue("@Ent_Numero", Ent_Numero)
        command.Parameters.AddWithValue("@Ent_Fecha", Ent_Fecha)
        command.Parameters.AddWithValue("@Ent_Hora", Ent_Hora)
        command.Parameters.AddWithValue("@Ent_Lugar", Ent_Lugar)
        command.Parameters.AddWithValue("@TEnt_Codigo", TEnt_Codigo)
        command.Parameters.AddWithValue("@Ent_Realizada", Ent_Realizada)
        command.Parameters.AddWithValue("@Ent_Detalle", Ent_Detalle)
        command.Parameters.AddWithValue("@Ent_Obs", Ent_Obs)
        command.Parameters.AddWithValue("@DVH", DVH)


        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Delete(conn As SqlConnection, Soli_Numero As Int32, Ent_Numero As Int16) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "dbo.delEntrevista"
        command.Parameters.AddWithValue("@Soli_Numero", Soli_Numero)
        command.Parameters.AddWithValue("@Ent_Numero", Ent_Numero)

        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Find(conn As SqlConnection, Soli_Numero As Int32, Ent_Numero As Int16) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getEntrevista"
        command.Parameters.AddWithValue("@Soli_Numero", Soli_Numero)
        command.Parameters.AddWithValue("@Ent_Numero", Ent_Numero)


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindPorSolicitud(conn As SqlConnection, Soli_Numero As Int32) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getEntrevista_PorSolicitud_All"
        command.Parameters.AddWithValue("@Soli_Numero", Soli_Numero)


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Shared ReadOnly Property Instance()
        Get
            If (m_Instance Is Nothing) Then
                m_Instance = New TDGEntrevista()
            End If

            Return m_Instance
        End Get
    End Property

    Private Sub New()

    End Sub

End Class
